/*Create Logins*/
IF  NOT EXISTS (SELECT * FROM sys.server_principals WHERE name = N'PortalAdmin')
CREATE LOGIN [PortalAdmin] WITH PASSWORD=N'IL0v3SQL', DEFAULT_DATABASE=[master], DEFAULT_LANGUAGE=[us_english], CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF
GO

IF NOT EXISTS (SELECT * FROM sys.server_principals WHERE name = N'PortalUser')
CREATE LOGIN [PortalUser] WITH PASSWORD=N'IL0v3SQL', DEFAULT_DATABASE=[master], DEFAULT_LANGUAGE=[us_english], CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF
GO

IF  NOT EXISTS (SELECT * FROM sys.server_principals WHERE name = N'DNNdbo')
CREATE LOGIN [DNNdbo] WITH PASSWORD=N'IL0v3SQL', DEFAULT_DATABASE=[master], DEFAULT_LANGUAGE=[us_english], CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF
GO

/*Create Database*/
USE [master]
GO

/****** Object:  Database [DNN-Installation-Test]    Script Date: 04/22/2009 00:18:36 ******/
IF  EXISTS (SELECT name FROM sys.databases WHERE name = N'DNN-Installation-Test')
ALTER DATABASE [DNN-Installation-Test] SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO

IF  EXISTS (SELECT name FROM sys.databases WHERE name = N'DNN-Installation-Test')
DROP DATABASE [DNN-Installation-Test]
GO

DECLARE @data_path nvarchar(256);
SET @data_path = (SELECT SUBSTRING(physical_name, 1, CHARINDEX(N'master.mdf', LOWER(physical_name)) - 1)
                  FROM master.sys.master_files
                  WHERE database_id = 1 AND file_id = 1);

/****** Object:  Database [DNN-Installation-Test]    Script Date: 04/22/2009 00:18:36 ******/
EXECUTE('CREATE DATABASE [DNN-Installation-Test] ON  PRIMARY 
( NAME = N''DotNetNuke-Install-Test'', FILENAME = '''+ @data_path + '\DotNetNuke-Install-Test.mdf'' , SIZE = 2048KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
 LOG ON 
( NAME = N''DotNetNuke-Install-Test-log'', FILENAME = '''+ @data_path + 'DotNetNuke-Install-Test.ldf'' , SIZE = 1024KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)'
);
GO

/*Create Database Permissions For Users*/
USE [DNN-Installation-Test]
GO

CREATE USER [PortalUser] FOR LOGIN [PortalUser]
GO

CREATE USER [PortalAdmin] FOR LOGIN [PortalAdmin]
GO

EXEC sp_addrolemember N'db_owner', N'PortalAdmin'
GO